package com.ksyun.alert.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ksyun.alert.entity.AlertMetricsDO;
import com.ksyun.alert.mapper.AlertMetricsMapper;
import com.ksyun.alert.service.AlertMetricsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 指标记录表接口实现层
 * @author 蓝
 */
@Service
public class AlertMetricsServiceImpl extends ServiceImpl<AlertMetricsMapper, AlertMetricsDO> implements AlertMetricsService {
    @Resource
    private AlertMetricsMapper alertMetricsMapper;

    @Override
    public void insert(AlertMetricsDO metrics) {
        alertMetricsMapper.insert(metrics);
    }

    @Override
    public Float selectRecordByAlertIdAneMetricName(Long alertId, String metricName) {
        LambdaQueryWrapper<AlertMetricsDO> wrapper = Wrappers.lambdaQuery(AlertMetricsDO.class)
                .eq(AlertMetricsDO::getRecordId, alertId)
                .eq(AlertMetricsDO::getMetricName, metricName);
        AlertMetricsDO alertMetricsDO = this.getOne(wrapper);
        return alertMetricsDO.getValue();
    }
}